﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PoshBuild.ComponentModel;
using System.ComponentModel;

namespace IronCow.Posh.ComponentModel
{
    [DisplayFormatDescriptor(typeof(Task))]
    public class TaskDisplayFormatDescriptor : IDisplayFormatDescriptor
    {
        #region IDisplayFormatDescriptor Members

        public DisplayFormatAttribute GetDisplayFormatAttribute()
        {
            return new DisplayFormatAttribute();
        }

        public DisplayFormatColumnAttribute GetDisplayFormatColumnAttribute(string propertyName)
        {
            switch (propertyName)
            {
                case "Name":
                    return new DisplayFormatColumnAttribute(0);
                case "ParentName":
                    return new DisplayFormatColumnAttribute(1, "List")
                    {
                        Width = 9
                    };
                case "Priority":
                    return new DisplayFormatColumnAttribute(2)
                    {
                        Width = 8
                    };
                case "Due":
                    return new DisplayFormatColumnAttribute(3)
                    {
                        Width = 10
                    };
                case "IsCompleted":
                    return new DisplayFormatColumnAttribute(4, "Complete")
                    {
                        Width = 8
                    };
                case "Tags":
                    return new DisplayFormatColumnAttribute(5, "Tags")
                    {
                        ScriptBlock = "$tags = new-object String[]($_.Tags.Count)\n" +
                                      "$_.Tags.CopyTo($tags, 0)\n" +
                                      "[String]::Join(',', $tags);"
                    };
                default:
                    return null;
            }
        }

        #endregion
    }
}
